Skip to content

Conversation

@eerhardt
Copy link
Member

Description

Set both RuntimeIdentifier/ContainerRuntimeIdentifier or RuntimeIdentifiers/ContainerRuntimeIdentifiers when building dotnet containers. This way the application is published correctly - for example for native AOT.

Set both RuntimeIdentifier/ContainerRuntimeIdentifier or RuntimeIdentifiers/ContainerRuntimeIdentifiers when building dotnet containers. This way the application is published correctly - for example for native AOT.
@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12936

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12936"

Copilot finished reviewing on behalf of eerhardt November 12, 2025 20:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances container image building for .NET projects by setting both RuntimeIdentifier/RuntimeIdentifiers and ContainerRuntimeIdentifier/ContainerRuntimeIdentifiers MSBuild properties when building dotnet containers. This ensures applications are published correctly for scenarios like Native AOT compilation. Additionally, the PR removes the ContainerRegistry property from several playground TestShop project files.

Key changes:

  • Sets RuntimeIdentifier alongside ContainerRuntimeIdentifier for single-platform builds
  • Sets RuntimeIdentifiers alongside ContainerRuntimeIdentifiers for multi-platform builds
  • Removes unused ContainerRegistry property from three TestShop playground projects

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs Adds RuntimeIdentifier/RuntimeIdentifiers properties to dotnet publish command for both single and multi-platform builds
playground/TestShop/MyFrontend/MyFrontend.csproj Removes ContainerRegistry property from project file
playground/TestShop/CatalogService/CatalogService.csproj Removes ContainerRegistry property from project file
playground/TestShop/BasketService/BasketService.csproj Removes ContainerRegistry property from project file

{
// Single platform - use ContainerRuntimeIdentifier
// Single platform - use RuntimeIdentifier/ContainerRuntimeIdentifier
arguments += $" /p:RuntimeIdentifier=\"{ridArray[0]}\"";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What was the failure mode here? From what I recall, we always just set ContainerRuntimeIdentifier since this was introduced in 9.4. Was this breaking AoT in some way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you aspire do build a project like this:

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishSelfContained>true</PublishSelfContained>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>

from a Windows machine, it is going dotnet publish that project on the current machine (Windows) and put it in a Linux docker image. So you end up with Windows exectuables and .dlls in the image, and obviously the image doesn't run correctly. Specifying both RuntimeIdentifier and ContainerRuntimeIdentifier fixes this because the app is published for linux-x64 and put in a linux-x64 image.

For PublishAot=true, we don't expect this scenario to actually work end-to-end. But at least now you get an error saying (when you use --log-level debug):

Microsoft.NETCore.Native.Publish.targets(60,5): error : Cross-OS native compilation is not
supported. [D:\DotNetTest\nettest\nettest.ApiService\nettest.ApiService.csproj]

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote escaping works for me on macOS although this is still just passing a single RID.

@eerhardt eerhardt merged commit c3b5f55 into dotnet:main Nov 18, 2025
296 checks passed
@eerhardt eerhardt deleted the FixContainerBuilder branch November 18, 2025 17:56
@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants